package com.cn.shuangzi.userinfo.activity;

import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;

import com.cn.shuangzi.SZBaseActivity;
import com.cn.shuangzi.activity.SZInterfaceActivity;
import com.cn.shuangzi.userinfo.R;
import com.cn.shuangzi.util.SZToast;
import com.cn.shuangzi.util.SZUtil;

/**
 * Created by CN.
 */

public abstract class SZBuyNotesActivity extends SZBaseActivity implements SZInterfaceActivity {
    private TextView txtNotes;
    private String email;
    @Override
    protected int onGetChildView() {
        return R.layout.activity_buy_notes;
    }

    @Override
    protected void onBindChildViews() {
        txtNotes = findViewById(R.id.txtNotes);
    }

    @Override
    protected void onBindChildListeners() {
    }

    @Override
    protected void onChildViewCreated() {
        onChildViewCreatedPre();
        showBackImgLeft(getBackImgLeft());
        setTitleTxt(R.string.txt_buy_notes);
        String desc = getString(R.string.txt_buy_notes_desc);
        email = getEmail() == null ? "service@shuangzikeji.cn" : getEmail();
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder(desc);
        stringBuilder.setSpan(new DescTextViewSpan(),
                desc.indexOf(email), desc.indexOf(email) + email.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        txtNotes.setText(stringBuilder);
        txtNotes.setHighlightColor(getResources().getColor(android.R.color.transparent));
        txtNotes.setMovementMethod(LinkMovementMethod.getInstance());
    }
    @Override
    protected void onReloadData(boolean isRefresh) {

    }
    private class DescTextViewSpan extends ClickableSpan {
        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(getResources().getColor(R.color.colorNotesEmail));
            ds.setUnderlineText(false);
        }

        @Override
        public void onClick(View widget) {
            SZUtil.copyClipboard(getActivity(),email);
            SZToast.success("邮箱地址已复制到剪贴板！");
        }
    }
    public abstract String getEmail();
}
